'''
@Project ：fastApiProject 
@File    ：user_service.py
@IDE     ：PyCharm 
@Author  ：xzy
@Date    ：2024/11/22 20:29 
@explain: 
'''

from fastapi import APIRouter
from config.mysql_config import get_db
from models.entities import PowerPlant

router = APIRouter(
    prefix="/user",
    tags=["user"],
    responses={404: {"description": "Not found"}}
)

@router.get('/getAll',tags=["users"])
def read_pow():
    with get_db() as db:
        powerPlants = db.query(PowerPlant).all()  # 查询所有记录
    return [{"id": plant.id,
             "power_plant_date": plant.power_plant_date,
             "month_power_generation": plant.month_power_generation,
             "unit": plant.unit} for plant in powerPlants]

